package com.dongdongshop.service.impl;

import com.dongdongshop.data.Page;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TypeTemplateService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class TypeTemplateImpl implements TypeTemplateService {
    @Autowired
    private TbTypeTemplateMapper tbTypeTemplateMapper;

    @Override
    public Page<TbTypeTemplate> fdindList(Integer pageNum, Integer pageSize, TbTypeTemplate typeTemplate) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbTypeTemplate> list = tbTypeTemplateMapper.selectByName(typeTemplate);
        PageInfo<TbTypeTemplate> pageInfo = new PageInfo<>(list);
        Page<TbTypeTemplate> page = new Page(pageInfo.getPageNum(),pageInfo.getPageSize(),pageInfo.getPages(),pageInfo.getList());
        return page;
    }

    @Override
    public void insert(TbTypeTemplate typeTemplate) {
        tbTypeTemplateMapper.insertSelective(typeTemplate);
    }

    @Override
    public void deleteInfo(Long[] ids) {
        tbTypeTemplateMapper.deleteInfo(ids);
    }

    @Override
    public TbTypeTemplate toUpdate(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer updateInfo(TbTypeTemplate typeTemplate) {
        return tbTypeTemplateMapper.updateByPrimaryKeySelective(typeTemplate);
    }

    @Override
    public List<TbTypeTemplate> show() {
        return tbTypeTemplateMapper.selectByExample(null);
    }

    @Override
    public TbTypeTemplate selectById(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }
}
